<?php

namespace App\Http\Controllers\WAP\User;

use Illuminate\Http\Request;
use Session,Config;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Service\User\UserService;



class UpdateController extends Controller
{
    //

    public function updatePassword(Request $request)
    {
        $where = $request->all();
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));
        $where['token'] = $token;

        $user  = new UserService();

        $data = $user->updatePassword($where);

        return response()->json($data);
    }

    public function updateEmail(Request $request)
    {
        $where = $request->all();
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));
        $where['token'] = $token;

        $user  = new UserService();

        $data = $user->updateEmail($where);
        if($data['error_code'] == '0')
        {
            Session::put(Config::get('custom.setting.MEMBER_EMAIL'), $where['email']);
        }

        return response()->json($data);
    }


    public function updateQQ(Request $request)
    {
        $where = $request->all();
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));
        $where['token'] = $token;

        $user  = new UserService();

        $data = $user->updateQQ($where);

        if($data['error_code'] == '0')
        {
            Session::put(Config::get('custom.setting.MEMBER_QQ'), $where['qq']);
        }

        return response()->json($data);
    }



    public function updatePhone(Request $request)
    {
        $where = $request->all();
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));
        $where['token'] = $token;

        $user  = new UserService();

        $data = $user->updatePhone($where);

        if($data['error_code'] == '0')
        {
            Session::put(Config::get('custom.setting.MEMBER_PHONE'), $where['phone']);
        }

        return response()->json($data);
    }
}
